
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Admin</title>
        <link href="${requestScope.ROOT}/css/bootstrap.min.css" rel="stylesheet">
        <link href="${requestScope.ROOT}/font-awesome/css/font-awesome.css" rel="stylesheet">
        <link href="${requestScope.ROOT}/css/sb-admin.css" rel="stylesheet">
        <link href="${requestScope.ROOT}/css/alert.css" rel="stylesheet">
        <style>
            #error {
                margin-top: 20px;
                padding-left: 10px;
                color: red;
                font-weight: bold;
            }
        </style>
        <script src="${requestScope.ROOT}/js/jquery-1.10.2.js"></script>
        <script src="${requestScope.ROOT}/js/bootstrap.min.js"></script>
        <script src="${requestScope.ROOT}/js/plugins/metisMenu/jquery.metisMenu.js"></script>
        <script src="${requestScope.ROOT}/js/sb-admin.js"></script>
        <script src="${requestScope.ROOT}/js/alert.js"></script>
        <script src="${requestScope.ROOT}/utils.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                window.history.forward(1);
                $(document).on("keyup", function(e) {
                    if (e.keyCode === 13) {
                        $('#button_submit').trigger("click");
                    }
                });
                if (getCookie("check")) {
                    $('input[name=remember]').prop('checked', true);
                    $('input[name=username]').val(getCookie("username"));
                    $('input[name=password]').val(getCookie("password"));
                } else {
                    $('input[name=username]').val(getCookie(""));
                    $('input[name=password]').val(getCookie(""));
                }
                $('#button_submit').bind("click", function(e) {

                    if ($('input[name=username]').val() === "" || $('input[name=password]').val() === "") {
                        Alert.render('Không được để trống Tên đăng nhập và mật khẩu');
                        $('input[name=username]').focus();
                        return false;
                    } else {
                        var username = $('input[name=username]').val();
                        var password = $('input[name=password]').val();
                        setCookie("username", username, 365);
                        setCookie("password", password, 365);
                    }
                    if ($('input[name=remember]').is(":checked")) {
                        setCookie("check", "ok", 365);
                    } else {
                        delete_cookie("check");
                        delete_cookie("username");
                        delete_cookie("password");
                    }
                    $('#loginForm').submit();
                    e.preventDefault();
                });

            });
        </script>
    </head>

    <body>
 
        <div id="dialogoverlay"></div>
        <div id="dialogbox">
            <div>
                <div id="dialogboxhead"></div>
                <div id="dialogboxbody"></div>
                <div id="dialogboxfoot"></div>
            </div>
        </div>
        <%
            if (session.getAttribute("user") != null) {
                response.sendRedirect("/my-web/admin?goto=home");
            }
        %>
        <div class="container">
            <div class="row">
                <div class="col-md-4 col-md-offset-4">
                    <c:if test="${not empty requestScope.error}" >

                        <div id="error">
                            <ul>
                                <c:forEach items="${requestScope.error}" var="item">
                                    <li><c:out value="${item}"/></li>
                                </c:forEach>
                            </ul>
                        </div>

                    </c:if>

                    <div class="login-panel panel panel-default" style="margin-top: 30px">
                        <div class="panel-heading">
                            <h3 class="panel-title">Đăng nhập</h3>
                        </div>
                        <div class="panel-body">
                            <form role="form" method="post" action="" id="loginForm">
                                <fieldset>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="Tên đăng nhập" name="username" type="user name" value="admin" autofocus/>
                                    </div>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="Mật khẩu" name="password" type="password" value="admin">
                                    </div>
                                    <div class="checkbox">
                                        <label>
                                            <input name="remember" type="checkbox" value="Remember Me">Ghi nhớ
                                        </label>
                                    </div>
                                    <a id ="button_submit" href="#" class="btn btn-lg btn-success btn-block">Đăng nhập</a>
                                </fieldset>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>

</html>
